//<script type="text/javascript">
    //<![CDATA[
    //    var <?php echo $id; ?>Left;
    //    var <?php echo $id; ?>Top;
    $(document).ready(function()
    {
        $("#<?php echo $id ?>").dialog({
            position: 'center',
            resizeable: false,
            autoOpen: false,
            dialogClass: '<?php echo $id ?>'
        });

        $("#<?php echo $id ?>").dialog('option', 'position', 'center');

//        $( window ).resize(function() {
//            $( "#<?php echo $id; ?>" ).dialog( "option", "position", $( "#<?php echo $id; ?>" ).dialog( "option", "position" ) );
//        });

        $('.fbutton').click(function()
        {
            //$("#<?php echo $id ?>").dialog('option', 'position', 'center');
            $("#<?php echo $id ?>").dialog('open');
        });

        $('#<?php echo $id ?>').bind('dialogopen', function(event, ui)
        {
            $('.fbutton').addClass('ui-state-active');
            $('.fbutton').removeClass('ui-state-default');
            $('.fbutton').click(function()
            {
                //$("#<?php echo $id ?>").dialog('option', 'position', 'center');
                $("#<?php echo $id ?>").dialog('close');
            });
        });

        $('#<?php echo $id ?>').bind('dialogclose', function(event, ui)
        {
            $('.fbutton').addClass('ui-state-default');
            $('.fbutton').removeClass('ui-state-active');
            $('.fbutton').click(function()
            {
                //$("#<?php echo $id ?>").dialog('option', 'position', 'center');
                $("#<?php echo $id ?>").dialog('open');
            });
        });

        $("#<?php echo $id ?>filterDropdown").change(<?php echo $id ?>Change);
        $("input[name='rankCheck[]']").change(<?php echo $id ?>Change);
    });

        function <?php echo $id ?>Change()
        {
            //<?php echo $id ?>Left = jQuery($(".<?php echo $id ?>")).position().left;
            //<?php echo $id ?>Top = jQuery($(".<?php echo $id ?>")).position().top;
            $(".<?php echo $name ?>data").remove();
            $('#<?php echo $name ?>Table').removeData('content_old');
            $('#<?php echo $name ?>Table tbody > tr').children().removeClass('ui-state-active').addClass('ui-widget-content');

            var filter = $("#<?php echo $id; ?>filterDropdown").val();
            filter = filter.split("|");
            var ranks = Array();
            $("input[name='rankCheck[]']:checked").each(function(i)
            {
                ranks.push($(this).val());
            });
            $("#<?php echo $name ?>Table tr").each(function(index)
            {
                if (index > 2)
                {
                    var row = $(this);
                    $(row).show();
                    var found = false;
                    // childNodes[0] -- Race
                    // childNodes[1] -- Class
                    // childNodes[2] -- Spec

                    jQuery.each(filter,function(i)
                    {
                        var s = $(row.children()[1]).html();
                        //var s = row.context.cells[1].innerHTML.replace("%20", " ");
                        var matchs = s.match(/\/images\/class\/(.*?)\.gif/);
                        f = this.split(":");
                        if (matchs && f && matchs[1] == f[0])
                        {
                            var t = $(row.children()[1]).html();
                            var matcht = t.match(/\/images\/talent\/(.*?)([0-9])\.jpg/);
                            if (matcht && f && matcht[2] == f[1])
                            {
                                var tankspec = $($($(row.context).children()[2]).children()[0]).html();
                                if (($($("#<?php echo $id; ?>filterDropdown").find('option').filter(':selected')[0]).html() == "Tanks" && (matchs[1] == "Druid" || matchs[1] == "Death Knight") && tankspec == "1") ||
                                    ($($("#<?php echo $id; ?>filterDropdown").find('option').filter(':selected')[0]).html() == "Melee DPS" && (matchs[1] == "Druid" || matchs[1] == "Death Knight") && tankspec == "0") ||
                                    (!($($("#<?php echo $id; ?>filterDropdown").find('option').filter(':selected')[0]).html() == "Tanks" && (matchs[1] == "Druid" || matchs[1] == "Death Knight"))) &&
                                    (!($($("#<?php echo $id; ?>filterDropdown").find('option').filter(':selected')[0]).html() == "Melee DPS" && (matchs[1] == "Druid" || matchs[1] == "Death Knight"))))
                                {
                                    $(row).show();
                                    found = true;
                                }
                            }
                        }
                    });
                    if (!found)
                    {
                        $(row).hide();
                    }
                    if (ranks.length > 0)
                    {
                        var found2 = false;
                        $(ranks).each(function(i)
                        {
                            var rank = ranks[i];
                            var r = $(row.children()[2]).text().substring(2);

                            if (found && r == rank)
                            {
                                $(row).show();
                                found2 = true;
                            }
                        })
                        if (!found2)
                        {
                            $(row).hide();
                        }
                    }
                }
            });
            //$("#<?php echo $id ?>").dialog('option', 'position', [<?php echo $id ?>Left,<?php echo $id ?>Top]);
        }
    //]]>
//</script>
